#include<iostream>

using namespace std;

int maxSum(int *p, int n)
{
	int max=p[0];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		if(sum>=0)
			sum+=p[i];
		else
			sum=p[i];
			
		if(sum>max)
			max=sum;
	}
	return max;
}

int main()
{
	//可以计算数组元素全部为负数的情况，个人感觉这个算法是最好的
	int p[] = {-13,-3,-25,-20,-3,-16,-23,-18,-20,-7,-12,-5,-22,-15,-4,-7};
	cout<<maxSum(p,16)<<endl;
	return 0;

}
